k=0
bp1=0
bp2=0
bp3=0
bp4=0
bp5=0
bp6=0
bp7=0
bp8=0
bp9=0
bp10=0
stop=0
a=int(input())
s=str(a)
s1=str(s[0])
s2=str(s[1])
s3=str(s[2])
s4=str(s[3])
prost1=int(s1+s2+s3+s4)
prost2=int(s1+s2+s3)
prost3=int(s2+s3+s4)
prost4=int(s1+s2)
prost5=int(s2+s3)
prost6=int(s3+s4)
prost7=int(s1)
prost8=int(s2)
prost9=int(s3)
prost10=int(s4)
#4digits
y=prost1
for i in range(2,y//2):
    if y%i==0:
        k=+1
if k==0:
    bp1=y
    stop=1
k=0

#3digits
y=prost2
for i in range(2,y//2):
    if y%i==0:
        k=+1
if k==0 and stop==0:
    bp2=y
k=0
y1=prost3
for i in range(2,y1//2):
    if y1%i==0:
        k=+1
if k==0 and stop==0 and y1>y:
    y=y1
    bp3=y
    stop=1
k=0

#2digits
y=prost4
for i in range(2,y//2):
    if y%i==0:
        k=+1
if k==0 and stop==0:
    bp4=y
k=0
y1=prost5
for i in range(2,y1//2):
    if y1%i==0:
        k=+1
if k==0 and stop==0 and y1>y:
    y=y1
    bp5=y
k=0
y2=prost6
for i in range(2,y2//2):
    if y2%i==0:
        k=+1
if k==0 and stop==0 and y2>y:
    y=y2
    bp6=y
    stop=1
k=0

#1digits
y=prost7
if y>3:
    for i in range(2,y//2):
        if y%i==0:
            k=+1
if y==4:
    k=1
if k==0 and stop==0:
    bp7=y
else:
    y=0
k=0
y1=prost8
if y1>3:
    for i in range(2,y1//2):
        if y1%i==0:
            k=+1
if y1==4:
    k=1
if k==0 and stop==0 and y1>y:
    y=y1
    bp8=y
else:
    y=0
k=0
y2=prost9
if y2>3:
    for i in range(2,y2//2):
        if y2%i==0:
            k=+1
if y2==4:
    k=1
if k==0 and stop==0 and y2>y:
    y=y2
    bp9=y
else:
    y=0
k=0
y3=prost10
if y3>3:
    for i in range(2,y3//2):
        if y3%i==0:
            k=+1
if y3==4:
    k=1
if k==0 and stop==0 and y3>y:
    y=y3
    bp10=y

if bp2>bp1:
    bp1=bp2
if bp3>bp1:
    bp1=bp3
if bp4>bp1:
    bp1=bp4
if bp5>bp1:
    bp1=bp5
if bp6>bp1:
    bp1=bp6
if bp7>bp1:
    bp1=bp7
if bp8>bp1:
    bp1=bp8
if bp9>bp1:
    bp1=bp9
if bp10>bp1:
    bp1=bp10
print(bp1)